#include <model3d.h>
#include <debug.h>
#include <stdlib.h>
#include <assert.h>


model3d_t *
model3d_new( uint16_t width, uint16_t height, uint16_t depth )
{
  model3d_t *m;

  m = calloc( 1, sizeof(*m) );

  if ( m != NULL )
    {
      m->size.x = width;
      m->size.y = height;
      m->size.z = depth;

      m->buffer = calloc( width * height * depth, sizeof( *(m->buffer) ) );

      if ( m->buffer == NULL )
	{
	  free( m );
	  m = NULL;
	  err( "Could not allocate memory for model3d!" );
	}
    }

  return m;
}

void
model3d_free( model3d_t *m )
{
  assert( m != NULL );
  if ( m->buffer != NULL )
    free( m->buffer );
  free( m );
}

